//
//  SKUDefultQuestionUserimageTBCell.m
//  ZITHER
//
//  Created by weixin on 2018/8/22.
//  Copyright © 2018年 weixn. All rights reserved.
//

#import "SKUDefultQuestionUserimageTBCell.h"

@implementation SKUDefultQuestionUserimageTBCell

- (void)awakeFromNib {
    [super awakeFromNib];
    [self.viewBack setCornerRadiusWithRadius:15 isMasks:YES];
    [self.viewBack setBorderWithColor:[UIColor RGBColorWithR:224 g:224 b:224] width:1];
    [self setMasonry];
}

-(void)setMasonry{
    
    [self.viewBack mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self).offset(0);
        make.left.equalTo(self).offset(14);
        make.right.equalTo(self).offset(-14);
        make.bottom.equalTo(self).offset(0);
    }];
    
    [self.labTakein mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self).offset(10);
        make.left.equalTo(self).offset(24);
        make.height.mas_equalTo(20);
    }];
    
    [self.Cardenter mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self).offset(10);
        make.right.equalTo(self).offset(-24);
        make.height.width.mas_equalTo(20);
    }];
    
    [self.price mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.labTakein.mas_bottom).offset(5);
        make.left.equalTo(self).offset(24);
        make.height.mas_equalTo(20);
    }];
    
    [self.viewText mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.labTakein.mas_bottom).offset(5);
        make.left.equalTo(self).offset(24);
        make.right.equalTo(self).offset(-24);
    }];
    
    [self.scrollview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.viewText.mas_bottom).offset(5);
        make.left.equalTo(self).offset(24);
        make.right.equalTo(self).offset(-24);
        make.height.mas_equalTo(60);
    }];
    
  
}
-(void)setIndexCell:(NSInteger)index{

    if (index == 0) {
        self.viewText.text = self.model.acceptSourceDesc;
        [self.viewBack setBorderWithColor:[UIColor RGBColorWithR:224 g:224 b:224] width:1];
        NSString *str = [NSString stringWithFormat:@"%@个接受的报价",self.model.acceptPriceCount];
        self.labTakein.text = str;//接受报价
        self.price.text = self.model.acceptPrice;//价格
        if (self.model.acceptFileList.count>0) {
            [self setScrImage:self.model.acceptFileList];
        }else{
            self.scrollview.hidden = YES;
        }
        
    }else if (index == 1){
        self.viewText.text = self.model.receiveSourceDesc;
        
        [self.viewBack setBorderWithColor:[UIColor RGBColorWithR:255 g:170 b:160] width:1];
        NSString *str = [NSString stringWithFormat:@"%@个待接受的报价",self.model.receivePriceCount];
        self.labTakein.text = str;//接受报价
        self.price.text = self.model.receivePrice;//价格
        str = [NSString stringWithFormat:@"%@%@",RootUrlImage,self.model.bizPortraitList];
        
        if (self.model.receiveFileList.count>0) {
            [self setScrImage:self.model.receiveFileList];
        }else{
            self.scrollview.hidden = YES;
        }
    }else{
        
        self.viewText.text = self.model.sourceDesc;
        [self.viewBack setBorderWithColor:[UIColor RGBColorWithR:224 g:224 b:224] width:1];
//        NSString *str = [NSString stringWithFormat:@"更多公开货源",self.model.openSourceCount];
        NSString *str = @"更多公开货源";
        self.labTakein.text = str;//接受报价
        self.price.hidden = YES;
        if (self.model.fileList.count>0) {
            [self setScrImage:self.model.fileList];
        }else{
            self.scrollview.hidden = YES;
        }
    }
}

-(void)setScrImage:(NSArray *)arr{
    self.scrollview.hidden = NO;
    [self.scrollview.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
    self.scrollview.contentSize = CGSizeMake(arr.count*68+15,0);
    
    for (int j = 0; j<arr.count; j++) {
        UIImageView * imageV = [[UIImageView alloc]initWithFrame:CGRectMake(j*68+15,0, 60,60)];
        
        [imageV setCornerRadiusWithRadius:5 isMasks:YES];
        imageV.backgroundColor = [UIColor randomColor];
        imageV.contentMode = UIViewContentModeScaleAspectFill;
        
        NSString *str = [NSString stringWithFormat:@"%@%@",RootUrlImage,arr[j]];
        
        [imageV sd_setImageWithURL:[NSURL URLWithString:str] placeholderImage:[UIImage imageNamed:@"watchSmale"]];
        
        [self.scrollview addSubview:imageV];
    }
    
}

@end
